s = 'hello world'
print(s[0]) # h
print(s[4]) # o
print(s[-1]) # d
# 切片
# 变量名[起始索引:结束索引+1:步数]
# 步数默认位 1
# 起始索引默认为 0
# 结束索引默认为 -1
print(s[0:4]) # hell 包头不包尾
print(s[6:9]) # wor
s2 = '123456789'
print(s2[0:9:2]) # 13579
print(s2[:9:2]) # 13579
print(s2[::2]) # 13579


# 字符串反转
# 步数：有方向，也需要反着
print(s2[-1:-10:-1])  # 987654321
print((s2[::-1])) # 987654321
